﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;

namespace GameLogic
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        private LogicBlock[,] field = new LogicBlock[10, 20];

        private int maxX = 10;
        private int maxY = 20;


        private Viewbox viewbox;
        private Label label;
        private string empty = "0";
        private string full = "A";

        private int xPosition = 5;
        private int yPosition = 0;

        public MainWindow()
        {
            DispatcherTimer timer = new DispatcherTimer();

            InitializeComponent();

            label = new Label();
            viewbox = new Viewbox();

            Content = viewbox;

            for (int y = 0; y < maxY; y++)
            {
                for (int x = 0; x < maxX; x++)
                {
                    field[x, y] = new LogicBlock();
                    label.Content += field[x, y].Type.ToString();
                }
                label.Content += "\n";
            }

            viewbox.Child = label;

            timer.Interval = TimeSpan.FromMilliseconds(90);
            timer.Tick += (s, a) =>
            {
                int tmpx = xPosition;
                int tmpy = yPosition;

                if(Keyboard.IsKeyDown(Key.A))
                {
                    xPosition = tmpx;
                    xPosition--;
                }
                if (Keyboard.IsKeyDown(Key.D))
                {
                    xPosition = tmpx;
                    xPosition++;
                }
                if (Keyboard.IsKeyDown(Key.S))
                {
                    yPosition = tmpy;
                    yPosition++;
                }

                field[tmpx, tmpy].Typ = empty;
                field[tmpx + 1, tmpy].Typ = empty;
                field[tmpx - 1, tmpy].Typ = empty;
                field[tmpx, tmpy + 1].Typ = empty;

                field[xPosition, yPosition].Typ = full;
                field[xPosition + 1, yPosition].Typ = full;
                field[xPosition - 1, yPosition].Typ = full;
                field[xPosition, yPosition + 1].Typ = full;

                label.Content = "";
                for (int y = 0; y < maxY; y++)
                {
                    for (int x = 0; x < maxX; x++)
                    {
                        label.Content += field[x, y].Typ;
                    }
                    label.Content += "\n";
                }

            };
            timer.Start();
        }
    }
}
